package com.ruoyi.classai.controller;

import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.classai.domain.EwcHomeworkSubmission;
import com.ruoyi.classai.service.IEwcHomeworkSubmissionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课后作业提交Controller
 * 
 * @author lcj
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/submission")
public class EwcHomeworkSubmissionController extends BaseController
{
    @Autowired
    private IEwcHomeworkSubmissionService ewcHomeworkSubmissionService;

    /**
     * 查询课后作业提交列表
     */
    @RequiresPermissions("classai:submission:list")
    @GetMapping("/list")
    public TableDataInfo list(EwcHomeworkSubmission ewcHomeworkSubmission)
    {
        startPage();
        List<EwcHomeworkSubmission> list = ewcHomeworkSubmissionService.list(Wrappers.query(ewcHomeworkSubmission));
        return getDataTable(list);
    }

    /**
     * 导出课后作业提交列表
     */
    @RequiresPermissions("classai:submission:export")
    @Log(title = "课后作业提交", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EwcHomeworkSubmission ewcHomeworkSubmission)
    {
        List<EwcHomeworkSubmission> list = ewcHomeworkSubmissionService.list(Wrappers.query(ewcHomeworkSubmission));
        ExcelUtil<EwcHomeworkSubmission> util = new ExcelUtil<EwcHomeworkSubmission>(EwcHomeworkSubmission.class);
        util.exportExcel(response, list, "课后作业提交数据");
    }

    /**
     * 获取课后作业提交详细信息
     */
    @RequiresPermissions("classai:submission:query")
    @GetMapping(value = "/getInfo/{homeworkSubmissionId}")
    public AjaxResult getInfo(@PathVariable("homeworkSubmissionId") Long homeworkSubmissionId)
    {
        return AjaxResult.success(ewcHomeworkSubmissionService.getById(homeworkSubmissionId));
    }

    /**
     * 新增课后作业提交
     */
    @RequiresPermissions("classai:submission:add")
    @Log(title = "课后作业提交", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody EwcHomeworkSubmission ewcHomeworkSubmission)
    {
        return toAjax(ewcHomeworkSubmissionService.save(ewcHomeworkSubmission));
    }

    /**
     * 修改课后作业提交
     */
    @RequiresPermissions("classai:submission:edit")
    @Log(title = "课后作业提交", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody EwcHomeworkSubmission ewcHomeworkSubmission)
    {
        return toAjax(ewcHomeworkSubmissionService.updateById(ewcHomeworkSubmission));
    }

    /**
     * 删除课后作业提交
     */
    @RequiresPermissions("classai:submission:remove")
    @Log(title = "课后作业提交", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{homeworkSubmissionIds}")
    public AjaxResult remove(@PathVariable Long[] homeworkSubmissionIds)
    {
        return toAjax(ewcHomeworkSubmissionService.removeByIds(Arrays.asList(homeworkSubmissionIds)));
    }
}
